package qz.lixinyu.modules.company.controller;

import java.util.Arrays;
import java.util.Map;

import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import qz.lixinyu.modules.company.entity.QyCompanyEntity;
import qz.lixinyu.modules.company.service.QyCompanyService;
import qz.lixinyu.common.utils.PageUtils;
import qz.lixinyu.common.utils.R;



/**
 * 
 *
 * @author lixinyu
 * @email 
 * @date 2025-02-25 16:03:35
 */
@Slf4j
@RestController
@RequestMapping("company/qycompany")
public class QyCompanyController {
    @Autowired
    private QyCompanyService qyCompanyService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("company:qycompany:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = qyCompanyService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("company:qycompany:info")
    public R info(@PathVariable("id") Long id){
		QyCompanyEntity qyCompany = qyCompanyService.getById(id);

        return R.ok().put("qyCompany", qyCompany);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("company:qycompany:save")
    public R save(@RequestBody QyCompanyEntity qyCompany){
		qyCompanyService.save(qyCompany);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("company:qycompany:update")
    public R update(@RequestBody QyCompanyEntity qyCompany){
		qyCompanyService.updateById(qyCompany);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("company:qycompany:delete")
    public R delete(@RequestBody Long[] ids){
		qyCompanyService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }
    /**
     * 投递简历    获得登录人的id发送sysUserEntity
     */
    @Transactional
    @RequestMapping ("/delivery")
    public R delivery(@RequestParam Map<String, Object> params){
        log.info("投递简历  param{}",params);
        Long id = Long.valueOf(params.get("id").toString());
        // 将 String 类型的 qyCompanyId 转换为 Long 类型
        Long qyCompanyId = Long.valueOf(params.get("qyCompanyId").toString());
        R r = qyCompanyService.saveCompanyAndQZ(id,qyCompanyId);
        return r;
    }
    /**
     * 显示通过率
     */
    @RequestMapping("/passRate")
    public R passRate(@RequestParam Long qyCompanyId){
        Double passRate = qyCompanyService.getPassRate(qyCompanyId);
        return R.ok().put("passRate",passRate);
    }
    /**
     * 通过分类过滤数据
     */
    @RequestMapping("/selectbycategorty")
    //@RequiresPermissions("company:qycompany:list")
    public R selectByCategorty(@RequestParam Map<String, Object> params){
        PageUtils page = qyCompanyService.queryPageByCategorty(params);

        return R.ok().put("page", page);
    }
    /**
     * 最新过滤
     */
    @RequestMapping("/getchangesortlist")
    public R getChangSortList(@RequestParam Map<String, Object> params){
        PageUtils page = qyCompanyService.getChangSortList(params);

        return R.ok().put("page", page);
    }
}
